package model

import "gorm.io/gorm"

const (
	OrderStateOver = iota
	OrderStateWaitPay
	OrderStateCancel
	OrderStateReturning
	OrderStateReturned
)

type Order struct {
	gorm.Model
	OrderNum string `gorm:"type:varchar(18);not null;"`
	UserId   int32  `gorm:"type:int(11);not null"`
	//GoodsId         int32  `gorm:"type:int(11);not null"`
	//Number   int32  `gorm:"type:tinyint(3);not null"`
	SumPrice string `gorm:"type:decimal(10,2);not null" `
	//OrderStatus     int32  `gorm:"type:tinyint(1);not null;default:1;comment:'订单状态0支付完成 1待支付 2取消支付 3退款中 4退款完成'"` //订单状态0支付完成 1待支付 2取消支付 3退款中 4退款完成
	//LogisticsStatus int32  `gorm:"type:tinyint(1);not null;default:1;comment:'物流状态 1待发货 2待收货 3已收货 4退货中 5退货完成'"`  //物流状态 1待发货 2待收货 3已收货 4退货中 5退货完成
	Status int32 `gorm:"type:tinyint(1)"` //0支付完成 1待支付 2取消支付
	//IsDelete   int32  `gorm:"type:tinyint(1);"` //0未删除 1删除
	//CreateTime string `gorm:"type:datetime(3)"`
	//UpdateTime string `gorm:"type:datetime(3)"`
	//DeleteTime sql.NullTime
}

func (Order) TableName() string {
	return "order"
}
func FindOrderById(id int32) (order *Order, err error) {
	if err := Db.Where("id = ?", id).First(&order).Error; err != nil {
		return nil, err
	}
	return order, nil
}

func DeleteOrder(id int32) error {
	err := Db.Where("id = ?", id).Delete(&Order{}).Error
	return err
}
